#include<iostream>
using namespace std;

struct edg
{
	int to, nxt, lenth;
}e[200005];
int head[20005] = {0};
int ind = 0;

void add(int a, int b, int c)
{
	e[++ind] = {b, head[a], c};	
	head[a] = ind;
}

int total_price = 0;
void dfs(int fa, int cur, int& child_nums, int n)
{
	for(int i = head[cur]; i; i = e[i].nxt)
	{
		int to_child_nums = 0;
		int to = e[i].to;
		if(to == fa) continue;
		child_nums += 1;
		dfs(cur, to, to_child_nums, n);
		child_nums += to_child_nums;	
		total_price += (n - to_child_nums - 1) * (to_child_nums + 1) * e[i].lenth;	
	}
}


int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		add(a, b, c);
		add(b, a, c);
	}	
	int nums = 0;
	dfs(0, 1, nums, n);
	cout << total_price << endl;

	return 0;
}
